home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / tools / sources / mkpat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  1.6 KB  |  65 lines

  1. /*****************************************************************************
  2.   FILE           : mkpat.c
  3.   SHORTNAME      : 
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : convert 8 bit raw file to snns pattern entry
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Ralf Huebner 
  10.   DATE           : 2.4.93
  11.  
  12.   CHANGED BY     : 
  13.   IDENTIFICATION : @(#)mkpat.c    1.5 2/28/94
  14.   SCCS VERSION   : 1.5
  15.   LAST CHANGE    : 2/28/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.  
  19. ******************************************************************************/
  20.  
  21. #include <stdio.h>
  22. #include <malloc.h>
  23.  
  24. #define RAWNUM 8
  25.  
  26. void main(int argc, char *argv[])
  27.  
  28. {
  29.    int i;
  30.    float out_val;
  31.    unsigned xsize, ysize;
  32.    unsigned char *buffer, *ptr, *limit;
  33.  
  34.    if ((argc!=3) || (int) strcmp(*++argv, "-h")==0 ) {
  35.       fprintf (stderr, "convert 8 bit raw file to snns pattern entry\n\n");
  36.       fprintf (stderr, "  usage: mkpat <xsize> <ysize>\n\n");
  37.       exit(0);
  38.    }
  39.    xsize = atol(*argv);
  40.    ysize = atol(*++argv);
  41.  
  42.    if ( (buffer=(unsigned char *)malloc(xsize*ysize) ) == NULL) {
  43.        fprintf (stderr, "ERROR: Can`t allocate memory\n");
  44.        exit(-1);
  45.    }
  46.    if ((unsigned char *)fread(buffer, xsize*ysize, 1, stdin) == NULL) {
  47.        fprintf (stderr, "ERROR: Can`t read from stdin\n");
  48.        exit(-1);
  49.    }
  50.    
  51.    i = 0;
  52.    limit = buffer + xsize*ysize;
  53.    
  54.    for(ptr=buffer; ptr<limit; ptr++) {
  55.       out_val = ((float) *ptr) / 255.0;
  56.       if ( ((i % xsize == 0) || (i % RAWNUM == 0)) && (i != 0) )
  57.           printf("\n");
  58.       i++;
  59.       printf ("%.3f ", out_val);
  60.    }
  61.   printf ("\n");
  62.   free(buffer);
  63. }
  64.    
  65.